package PackagesTests;

import Utils.*;
import ArithUtils.*;
import ArithmeticObjects.BTField;
import ArithmeticObjects.VerfGroup;
import ArithmeticObjects.VerfGroup.VElement;
import ArithmeticObjects.staticTypes;
import CryptoPrim.*;

/**
 * A tester class for Arithmetic packages.
 * 
 * @author shirpele
 */
public class ArithTest {
	public static void main(String [ ] args){
		BTField<BigNumber> fl = staticTypes.getNumberField(new BigNumber(13));
		BTField<BigNumber>.BTElement five = fl.getElement(new BigNumber(5));
		BTField<BigNumber>.BTElement seven = fl.getElement(new BigNumber(7));
		System.out.println(fl.pow(five, BigNumber.TWO).getValue());
		System.out.println(fl.inverse(five).getValue());
		System.out.println(fl.rightAdj(seven, five).getValue());
		System.out.println(fl.subtract(seven, five).getValue());

		System.out.println(fl.add(seven, five).getValue());
		System.out.println(fl.mult(seven, five).getValue());
		System.out.println(fl.subtract(seven, five).getValue());
		System.out.println(fl.rightAdj(seven, five).getValue());
		System.out.println(fl.addInverse(seven).getValue());
		System.out.println(fl.inverse(seven).getValue());
		
		//VerfGroup G = new VerfGroup("P-192");
		//VerfGroup G = new VerfGroup(new BigNumber(2), new BigNumber(2), new BigNumber(1));
		/*G.getByteTreeRep();
		VElement e = G.getGenerator();
		G.getOrder();
		VElement u =  G.getUnit();
		G.ElementIsEqual(u, u);
		VElement res1 = G.mult(e, u);
		VElement res2 = G.getElement(res1.toByteTree());
		System.out.println(G.ElementIsEqual(e, res2));
		G.ElementIsEqual(u, u);
		G.ElementIsEqual(e, u);
		System.out.println(e.getValue().getValue().toString());
		System.out.println(u.getValue().getValue().toString());
		G.inverse(e);
		System.out.println(G.pow(e, new BigNumber(12345)).getValue().getValue());
		G.rightAdj(u, u);
		G.getElement(G.toByteTree(e));
		System.out.println(G.ElementIsEqual(e, e));

		G.ElementIsEqual(u, u);
		System.out.println(G.ElementIsEqual(e, u));*/

		//G.ElementIsEqual(u, u);
		//System.out.println("done!");
		//int N = 100;
		//int nr = 100;
		PRG prg = new PRG(new HashFunction("SHA-256"));
		byte[] seed = TypeConvertionUtils.hexStringToByteArr("a4db1b772394c6d819a69b6e6d2f992d9e74b74492fcdd1643ca887837e09a78");
		prg.setSeed(seed);
		VerfGroup Gq = new VerfGroup("P-256");
		
		
		ByteTree bt1 = new ByteTree(TypeConvertionUtils.hexStringToByteArr("00000000020100000021003b4a9d4e365e2d209ac82c048f1c1f068ab75ffa20f2d1d7caf165552fd7c260010000002100cfc42d570aa282a71dde6d3d66331f8f4713340421c05baeecff86cb598ae9ef"));
		ByteTree bt2 = new ByteTree(TypeConvertionUtils.hexStringToByteArr("0000000002010000002100d2568c43d9fe77c284d80fc892ff7c4a0c85d44f1b00d1b2efd4f30e1006c5e90100000021005abedefd929209566e274972115bb06908f3dfee4536bb150e4471a839e6ebc7"));
		ByteTree bt3 = new ByteTree(TypeConvertionUtils.hexStringToByteArr("00000000020100000021006c8d49e5d4b9fb13fbe1089f3fa3c230b0f12464b01dcdab59057ff3dd4707d90100000021004ffbdf1ccdbbea4e8662974ad119d23f746e81479966fb154a71f49b6708f498"));
		System.out.println(bt1);
		System.out.println(bt2);
		System.out.println(bt3);
		System.out.println(bt1.getTheNChild(0).getBigNum()+" "+bt1.getTheNChild(1).getBigNum());
		VElement res = Gq.getElement(bt1);
		VElement m1 = Gq.getElement(bt2);
		VElement m2 = Gq.getElement(bt3);
		VElement m = Gq.mult(m1,m2);
		System.out.println(m.toByteTree());
		System.out.println(bt1);
		System.out.println(Gq.ElementIsEqual(res,m));
		
		
	}
	}

